package com.gxa.service.impl;

import com.gxa.mapper.DoctorMapper;
import com.gxa.pojo.Doctor;
import com.gxa.service.DoctorService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.print.Doc;
import java.util.List;
import java.util.Map;

/**
 * @Author 杨天可
 * @Date 2020/9/22 14:25
 * @Version 1.0
 */

@Service("doctorService")
public class DoctorServiceImpl implements DoctorService {

    @Resource
    DoctorMapper doctorMapper;


    //根据当前对象的ID删除
    @Override
    @Transactional(isolation = Isolation.DEFAULT,rollbackFor = {Throwable.class},propagation = Propagation.REQUIRED)
    public Integer deleteById(Integer id) {
        return doctorMapper.deleteById(id);
    }


    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.SUPPORTS,rollbackFor = {Throwable.class})
    //管理员模块--->医生管理--->查看医生
    public Map findById(Integer id) {
        return doctorMapper.selectById(id); }

    @Override
    //用户端--->我的医生模块--->查看医生详细信息
    public Map findDoc(Integer id) {
        return doctorMapper.findDoc(id);
    }

    @Override
    // 事务的管理
    @Transactional(isolation = Isolation.DEFAULT,rollbackFor = {Throwable.class},propagation = Propagation.REQUIRED)
    //管理员模块--->医生管理--->新增医生
    public Integer insert(Doctor doctor) {
        return  doctorMapper.insert(doctor);
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.SUPPORTS,rollbackFor = {Throwable.class})
    //管理员模块--->医生管理：根据姓名、所属医院查询
    public Map  findByNameHospital (String name,Integer hospitalId) {
        Map map = doctorMapper.selectByNameHospital(name, hospitalId);
        return  map; }

    @Override
    //管理员模块--->医生管理 & 用户端--->我的医生模块--->所有医生的信息显示、医生详情页  的分页查询
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.SUPPORTS,rollbackFor = {Throwable.class})
    public List<Map<String,Object>>  findByLimit() { return doctorMapper.selectAll(); }

    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,rollbackFor = {Throwable.class})
    //管理员模块--->医生管理--->编辑医生信息
    public int updateByid(Doctor doctor) {
        return doctorMapper.updateById(doctor); }
}
